<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function multiply(a, b) {
      return a * b
    }
    console.log(multiply(2, 0.0003));

    function len(num) {
      var str = num.toString();
      var index = str.indexOf('.');
      return index == -1 ? 0 : str.length - index - 1;
    }

    function solution(a, b) {
      var length = Math.pow(10, len(a) + len(b));
      return a * length * b / length;
    }

    console.log(solution(0, 0.001));
    console.log(solution(0.001, 0.001));
    console.log(solution(3, 0.001));
    console.log(solution(1000, 0.001));
  </script>
</body>

</html>